#include <allegro.h>
#include "mouvement.h"
#include "chargement.h"



int main() {
BITMAP *Buffer;
//BITMAP *Buffer2;
BITMAP *Image;
BITMAP *Image2;
BITMAP *background;
perso chikh ; perso body;
//monster sanglier;
int i=0; int o,o1; int j,k,t,v;
 
/* General initialization function */
	allegro_init();
	if (install_keyboard() == -1) {
	allegro_message("Error! %s", allegro_error);
	return -1;
	}
	set_color_depth(16);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) != 0) {
	set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
	allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
	return 1;
	}


Buffer = create_bitmap(800, 600);
//Buffer2 = create_bitmap(800, 600);
//loading background
background = load_bitmap("./Projet/background.bmp", NULL);

// mouvement Chikhimself
/*chikh.right[0] = load_bitmap("./Projet/chikh/mvt/right0.bmp", NULL);
chikh.right[1] = load_bitmap("./Projet/chikh/mvt/right1.bmp", NULL);
chikh.right[2] = load_bitmap("./Projet/chikh/mvt/right2.bmp", NULL);
chikh.right[3] = load_bitmap("./Projet/chikh/mvt/right3.bmp", NULL);

chikh.left[0] = load_bitmap("./Projet/chikh/mvt/0.bmp", NULL);
chikh.left[1] = load_bitmap("./Projet/chikh/mvt/1.bmp", NULL);
chikh.left[2] = load_bitmap("./Projet/chikh/mvt/2.bmp", NULL);
chikh.left[3] = load_bitmap("./Projet/chikh/mvt/3.bmp", NULL);*/

loadmvt (chikh,right,chikh,4);
loadmvt (chikh,left,chikh,4);
chikh.c[0]=0; chikh.c[1]=520;

//Attaque chikhimself
/*chikh.attackL[0] = load_bitmap("./Projet/chikh/attack/right0.bmp", NR
chikh.attackL[1] = load_bitmap("./Projet/chikh/attack/right1.bmp", NULL);
chikh.attackL[2] = load_bitmap("./Projet/chikh/attack/right2.bmp", NULL);
chikh.attackR[0] = load_bitmap("./Projet/chikh/attack/0.bmp", NULL);
chikh.attackR[1] = load_bitmap("./Projet/chikh/attack/1.bmp", NULL);
chikh.attackR[2] = load_bitmap("./Projet/chikh/attack/2.bmp", NULL);
chikh.attackR[3] = load_bitmap("./Projet/chikh/attack/3.bmp", NULL);
chikh.attackR[4] = load_bitmap("./Projet/chikh/attack/4.bmp", NULL);
chikh.attackR[5] = load_bitmap("./Projet/chikh/attack/5.bmp", NULL);
chikh.attackR[6] = load_bitmap("./Projet/chikh/attack/6.bmp", NULL);
chikh.attackR[7] = load_bitmap("./Projet/chikh/attack/7.bmp", NULL);
chikh.attackR[8] = load_bitmap("./Projet/chikh/attack/8.bmp", NULL);*/

// mouvement Body 
/*body.right[0] = load_bitmap("./Projet/body/mvt/right0.bmp", NULL);
body.right[1] = load_bitmap("./Projet/body/mvt/right1.bmp", NULL);
body.right[2] = load_bitmap("./Projet/body/mvt/right2.bmp", NULL);
body.right[3] = load_bitmap("./Projet/body/mvt/right3.bmp", NULL);
body.left[0] = load_bitmap("./Projet/body/mvt/0.bmp", NULL);
body.left[1] = load_bitmap("./Projet/body/mvt/1.bmp", NULL);
body.left[2] = load_bitmap("./Projet/body/mvt/2.bmp", NULL);
body.left[3] = load_bitmap("./Projet/body/mvt/3.bmp", NULL);*/
loadmvt (body,right,body,4);
loadmvt (body,left,body,4);
body.c[0]=20; body.c[1]=440;

//Attaque Body
body.attackR[0] = load_bitmap("./Projet/body/attack/0.bmp", NULL);
body.attackR[1] = load_bitmap("./Projet/body/attack/1.bmp", NULL);
body.attackR[2] = load_bitmap("./Projet/body/attack/2.bmp", NULL);
body.attackR[3] = load_bitmap("./Projet/body/attack/3.bmp", NULL);
body.attackR[4] = load_bitmap("./Projet/body/attack/4.bmp", NULL);
body.attackR[5] = load_bitmap("./Projet/body/attack/5.bmp", NULL);

body.attackL[0] = load_bitmap("./Projet/body/attack/0b.bmp", NULL);
body.attackL[1] = load_bitmap("./Projet/body/attack/1b.bmp", NULL);
body.attackL[2] = load_bitmap("./Projet/body/attack/2b.bmp", NULL);
body.attackL[3] = load_bitmap("./Projet/body/attack/3b.bmp", NULL);
body.attackL[4] = load_bitmap("./Projet/body/attack/4b.bmp", NULL);
body.attackL[5] = load_bitmap("./Projet/body/attack/5b.bmp", NULL);

// mouvement Sanglier
/*sanglier.right[0] = load_bitmap("./Projet/sanglier/mvt/right0.bmp", NULL);
sanglier.right[1] = load_bitmap("./Projet/sanglier/mvt/right1.bmp", NULL);
sanglier.right[2] = load_bitmap("./Projet/sanglier/mvt/right2.bmp", NULL);
sanglier.left[0] = load_bitmap("./Projet/sanglier/mvt/left0.bmp", NULL);
sanglier.left[1] = load_bitmap("./Projet/sanglier/mvt/left1.bmp", NULL);
sanglier.left[2] = load_bitmap("./Projet/sanglier/mvt/left2.bmp", NULL);*/
//sanglier->x=0; sanglier->y=SCREEN_H/2;

	
	// Verfification des images
	/*if (Image == NULL && Background == NULL) 
	{
	allegro_message("could not load images");
	allegro_exit();
	}*/

i=0; j=0; k=0; t=0;
Image = chikh.right[0];
Image2 = body.right[0];
blit(background, screen ,0,0,0,0, SCREEN_W,SCREEN_H);
draw_sprite(Buffer,Image, chikh.c[0], chikh.c[1]);
draw_sprite(Buffer,Image2, body.c[0], body.c[1]);

while (!key[KEY_ESC]) {
		
	// CHIKHIMSELF 
	
	if (key[KEY_RIGHT]) 
	{
		clear_bitmap(Buffer);
		i++;
		RIGHT (Image,chikh,i)
		o = 0;
	}

	if (key[KEY_LEFT]) 
	{
		clear_bitmap(Buffer);
		j++;
		LEFT (Image,chikh,i)
		o = 1;
	}

	
	if (key[KEY_SPACE])
	{
		
	}
	
	/*if (key[KEY_4]&& o=0) 
	{
		clear_bitmap(Buffer);
		i++;
		chikh->x++;
		//clear_bitmap(Image);
		Image = chikh.attackL[(i-1)%3];
		draw_sprite(Buffer,Image, chikh->x, chikh->y);
		o = 0;
	}*/

	// BODY ANIS

	if (key[KEY_D]) 
	{
		clear_bitmap(Buffer);
		t++;
		body.c[0]=body.c[0]+10;
		Image2 = body.right[(t-1)%4];
		o1 = 1;
	}



	if (key[KEY_Q]) 
	{
		clear_bitmap(Buffer);
		t++;
		body.c[0]=body.c[0]-10;
		Image2 = body.left[(t-1)%4];
		o1 = 0;
	}

	if (key[KEY_A])
	{	
		if (o1==1)
		{
		for(v=0;v<32;v++)
		{
			clear_bitmap(Buffer);
			k++;
			body.c[0]=body.c[0]+10;
			Image2 = body.attackR[(k-1)%6];				
			draw_sprite(Buffer,Image, chikh.c[0], chikh.c[1]);
			draw_sprite(Buffer,Image2, body.c[0], body.c[1]);
			blit(Buffer, screen ,0,0,0,0, SCREEN_W, SCREEN_H);
			rest(1);
		}
		if (o1 == 0)
		{
			for(v=0;v<32;v++)
		{
			clear_bitmap(Buffer);
			k++;
			body.c[0]=body.c[0]-10;
			Image2 = body.attackL[(k-1)%6];				
			draw_sprite(Buffer,Image, chikh.c[0], chikh.c[1]);
			draw_sprite(Buffer,Image2, body.c[0], body.c[1]);
			blit(Buffer, screen ,0,0,0,0, SCREEN_W, SCREEN_H);
			rest(1);
		}}
	}
	}

	/*if (key[KEY_E]&& o=0) 
	{
		clear_bitmap(Buffer);
		i++;
		body->x--;
		//clear_bitmap(Image);
		Image = body.attackL[(i-1)%3];
		draw_sprite(Buffer,Image, body->x, body->y);
		o = 0;
	}*/
	blit(background, Buffer ,0,0,0,0, SCREEN_W, SCREEN_H);
	draw_sprite(Buffer,Image, chikh.c[0], chikh.c[1]);
	draw_sprite(Buffer,Image2, body.c[0], body.c[1]);
	blit(Buffer, screen ,0,0,0,0, SCREEN_W, SCREEN_H);
	rest (1);
	}
readkey();
destroy_bitmap(Image);
destroy_bitmap(Buffer);
return 0;
}
END_OF_MAIN();
